﻿using System;
using System.Runtime.Serialization;
using EzDesk.Core.Model;

namespace EzDesk.Apps.Model.Attendance
{
    /// <summary>
    /// 描述一天的出勤考勤情况
    /// </summary>
    public partial class DayAttendanceEvaluation
    {
        private bool _late;
        private bool _isLeaveEarly;

        public DayAttendanceEvaluation()
        {
            Id = Guid.Empty;
        }

        
        /// <summary>
        /// 是否迟到
        /// </summary>
        [DataMember]
        public bool IsLate
        {
            get
            {
                return LateMiniutes > 0;
            }
            set { _late = value; }
        }


        /// <summary>
        /// 是否早退
        /// </summary>
        [DataMember]
        public bool IsLeaveEarly
        {
            get
            {
                return EarlyMiniutes > 0;
            }
            set { _isLeaveEarly = value; }
        }
        

    }

    public static class DayEvaluationExtension
    {
        /// <summary>
        /// 将分钟为单位的工时转换为以小时为单位精确到0.5小时的工时
        /// </summary>
        /// <param name="miniutes"></param>
        /// <returns></returns>
        public static int ToManhours(this Int32 miniutes)
        {
            return miniutes / 6 / 5 * 5;
        }

        public static string GetEvaluationStatusString(this DayAttendanceEvaluation source)
        {
            if (source.IsAbsense) return "旷工";

            if (source.IsExtraWork) return "加班";


            return (source.IsLate ? "迟到" : "") + (source.IsExtraWork ? "早退" : "");
        }
    }
}